// 接口： 在TypeScript里，接口的作用就是为这些类型命名和为你的代码或第三方代码定义契约。
/* 1. 对象类型  键值对 */
interface Person {
  // 必须属性
  name: string;
  sex: string;
  like: string;
  // 可选属性
  age?: number;
  // 只读属性
  readonly code: number;
  // 格外属性
  [propsName: string]: any;
}

const person: Person = {
  code: 110,
  name: "张三",
  sex: "男",
  like: "1231231",
  // age: 18,

  height: 180,
  weight: 90,
  marry: false,
};

/* 2. 函数类型 */
interface Add {
  (a: number, b: number): number;
}

const add123: Add = (a: number, b: number): number => {
  return a + b;
};

/* 3. 可索引的类型 */

interface Arr {
  [propsName: number]: string | boolean | number;
}

const arr11: number[] = [1, 2, 3, 4];
const arr22: Array<number> = [1, 2, 3, 4];

const arr33: Arr = ["a", "b", "c", "d", false, 123];

/* 4. 类类·型 */
interface IAnimal {
	type: string
	age: number
}


class Animal implements IAnimal {
  type: string;
  age: number;
  constructor(type: string, age: number) {
    this.type = type;
    this.age = age;
  }
}

const cat = new Animal("猫", 2);
const dog = new Animal("狗", 3);

console.log(cat, dog);

